<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;

// 用户认证相关路由(无需登录)
Route::group('user', function () {
    Route::post('login', 'user.AuthController/login');
    Route::post('wx_login', 'user.AuthController/miniLogin');
    Route::get('mp_auth_url', 'user.AuthController/getMpAuthUrl');
    Route::get('mp_login', 'user.AuthController/mpLogin');
    Route::post('mini_login', 'user.AuthController/miniLogin');
    Route::post('mobile_login', 'user.AuthController/mobileLogin');
    Route::post('send_code', 'user.AuthController/sendSmsCode');
});

// 需要用户登录的路由组
Route::group('user', function () {
    // 地区相关路由
    Route::group('area', function () {
        Route::get('tree', 'user.AreaController/tree');
        Route::get('children/:id', 'user.AreaController/children');
    });
    
    // 用户地址相关路由
    Route::group('address', function () {
        Route::get('list', 'user.AddressController/list');
        Route::post('add', 'user.AddressController/add');
        Route::post('edit', 'user.AddressController/edit');
        Route::post('delete', 'user.AddressController/delete');
    });
    
    // 订单相关路由
    Route::group('order', function () {
        Route::get('list', 'user.OrderController/list');
        Route::post('create', 'user.OrderController/create');
        Route::post('cancel', 'user.OrderController/cancel');
        Route::get('detail/:id', 'user.OrderController/detail');
    });
    
    // 钱包相关路由
    Route::group('wallet', function () {
        Route::get('info', 'user.WalletController/info');
        Route::post('recharge', 'user.WalletController/recharge');
        Route::post('withdraw', 'user.WalletController/withdraw');
    });
    
    // 会员套餐相关路由
    Route::group('package', function () {
        Route::get('list', 'user.UserPackageController/list');
        Route::post('buy', 'user.UserPackageController/buy');
    });
    
})->middleware(\app\middleware\UserAuth::class);

// API回调相关路由
Route::group('api', function () {
    Route::post('notify/wechat', 'api.NotifyController/wechat');
    Route::post('notify/alipay', 'api.NotifyController/alipay');
    Route::any('kuaidi100', 'api.Kuaidi100Controller/notify');
});

// 平台管理端路由组
Route::group('admin', function () {
    // 不需要验证的路由
    Route::post('login', 'AuthController/login');
    Route::post('logout', 'AuthController/logout');
    
    // 需要验证的路由组
    Route::group(function () {
        Route::get('info', 'AuthController/info');
        // 用户管理
        Route::get('user/list', 'UserController/list');
        Route::get('user/detail', 'UserController/detail');
        Route::post('user/update', 'admin.UserController/update');
        Route::post('user/disable', 'admin.UserController/disable');
        Route::post('user/enable', 'admin.UserController/enable');
        
        // 商家管理
        Route::get('merchant/list', 'MerchantController/list');
        Route::get('merchant/detail', 'MerchantController/detail');
        Route::post('merchant/audit/:id', 'MerchantController/audit');
        Route::post('merchant/status/:id', 'MerchantController/status');
        Route::get('merchant/fundFlow', 'MerchantController/fundFlow');
        
        // 订单管理
        Route::get('order/list', 'OrderController/list');
        Route::post('order/export', 'OrderController/export');
        Route::get('order/detail/:id', 'OrderController/detail');
        Route::post('order/refund', 'OrderController/refund');
        
        // 领券订单管理
        Route::get('coupon_order/list', 'CouponOrderController/list');
        Route::get('coupon_order/detail/:id', 'CouponOrderController/detail');
        Route::post('coupon_order/export', 'CouponOrderController/export');
        
        
        // 快递服务商管理
        Route::get('express_provider/list', 'ExpressServiceProviderController/list');
        Route::post('express_provider/add', 'ExpressServiceProviderController/add');
        Route::post('express_provider/update/:id', 'ExpressServiceProviderController/update');
        Route::post('express_provider/delete/:id', 'ExpressServiceProviderController/delete');
        
        // 用户消息场景配置管理
        Route::get('message_setting/list', 'MessageSettingController/list');
        
        //消息模板配置管理
        Route::get('message_template/list', 'MessageTemplateController/list');
        Route::post('message_template/update/:id', 'MessageTemplateController/update');
        Route::post('message_template/add', 'MessageTemplateController/add');
        Route::post('message_template/delete/:id', 'MessageTemplateController/delete');
        // 系统配置管理
        Route::get('platform_config/list', 'PlatformConfigController/list');
        Route::post('platform_config/update', 'PlatformConfigController/update');
        Route::get('platform_config/groups', 'PlatformConfigController/groups');
        Route::get('platform_config/getGroup/:group', 'PlatformConfigController/getGroup');
      
        // 管理员角色管理
        Route::get('role/list', 'RoleController/list');
        Route::post('role/add', 'RoleController/add');
        Route::post('role/update/:id', 'RoleController/update');
        Route::post('role/delete/:id', 'RoleController/delete');
        Route::get('role/permissions', 'RoleController/permissions');

        // 管理员账号管理
        Route::get('admin_user/list', 'AdminController/list');
        Route::post('admin_user/add', 'AdminController/add');
        Route::post('admin_user/update', 'AdminController/update');
        Route::post('admin_user/delete', 'AdminController/delete');
        
        // 操作日志
        Route::get('operation_log/list', 'PlatformOperationLogController/list');
        
        // 数据统计
        Route::get('statistics/overview', 'StatisticsController/overview');
        Route::get('statistics/order', 'StatisticsController/order');
        Route::get('statistics/finance', 'StatisticsController/finance');
        
    })->middleware(\app\middleware\AdminAuthMiddleware::class);
    
})->prefix('admin.')->middleware(\app\middleware\CrossDomain::class);

